/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_EXTENED_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_EXTENED_H

#include "drawable_descriptor.h"
#include "native_node.h"
#include "native_type.h"
#include "resource.h"

#include "frameworks/core/interfaces/arkoala/arkoala_api.h"
#include "interfaces/inner_api/drawable_descriptor/drawable_descriptor.h"
#ifdef OHOS_PLATFORM
#include "pixelmap_native_impl.h"
#else
#include "drawable_descriptor.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
struct Keels_ArkUI_LayoutConstraint {
    /** 元素最小宽度。 */
    int32_t minWidth;
    /** 元素最小高度。 */
    int32_t minHeight;
    /** 元素最大宽度。 */
    int32_t maxWidth;
    /** 元素最小宽度。 */
    int32_t maxHeight;
    /** 元素宽度百分比基准。 */
    int32_t percentReferWidth;
    /** 元素高度百分比基准。*/
    int32_t percentReferHeight;
};

/**
 * @brief 定义自定义组件回调事件的参数类型。
 *
 * @since 12
 */
struct ArkUI_CustomNodeAsyncEvent {
    /** 数据数组对象。*/
    Keels_ArkUI_NumberValue data[KEELS_MAX_COMPONENT_EVENT_ARG_NUM];
};

/**
 * 定义组件绘制上下文类型结构。
 *
 * @since 12
 */
struct Keels_ArkUI_DrawContext {
    /** 画布宽度。*/
    int32_t width;
    /** 画布高度。*/
    int32_t height;
    /** 绘制的画布。*/
    void* canvas;
};

/**
 * @brief 定义自定义组件事件的通用结构类型。
 *
 * @since 12
 */
struct Keels_ArkUI_NodeCustomEvent {
    int32_t targetId;
    Keels_ArkUI_NodeHandle node;
    ArkUICustomNodeEvent* event;
    Keels_ArkUI_LayoutConstraint constraint;
    void* userData;
};

struct ArkUI_OptionalFloat {
    int32_t isSet;
    float value;
};

struct ArkUI_OptionalInt {
    int32_t isSet;
    int32_t value;
};

struct ArkUI_OptionalUint {
    int32_t isSet;
    uint32_t value;
};

struct ArkUI_OptionalCharPtr {
    int32_t isSet;
    const char* value;
};

struct Keels_ArkUI_SwiperIndicator {
    Keels_ArkUI_SwiperIndicatorType type;
    ArkUI_OptionalFloat dimLeft;
    ArkUI_OptionalFloat dimTop;
    ArkUI_OptionalFloat dimRight;
    ArkUI_OptionalFloat dimBottom;
    ArkUI_OptionalFloat itemWidth;
    ArkUI_OptionalFloat itemHeight;
    ArkUI_OptionalFloat selectedItemWidth;
    ArkUI_OptionalFloat selectedItemHeight;
    ArkUI_OptionalInt maskValue;
    ArkUI_OptionalUint colorValue;
    ArkUI_OptionalUint selectedColorValue;
    ArkUI_OptionalInt maxDisplayCount;
};

struct Keels_ArkUI_DrawableDescriptor {
    Keels_OH_PixelmapNativeHandle pixelMap;
    Keels_OH_PixelmapNativeHandle* pixelMapArray;
    ArkUI_Int32 size;
    std::shared_ptr<Keels::Ace::Napi::DrawableDescriptor> drawableDescriptor;
    std::shared_ptr<Keels::Ace::Napi::AnimatedDrawableDescriptor> animatedDrawableDescriptor;
    std::shared_ptr<Keels::Ace::Napi::LayeredDrawableDescriptor> layeredDrawableDescriptor;
    std::shared_ptr<ArkUI_Resource> resource;
};

struct Keels_ArkUI_AccessibilityState {
    ArkUI_OptionalInt isDisabled;
    ArkUI_OptionalInt isSelected;
    ArkUI_OptionalInt checkedType;
};

struct Keels_ArkUI_AccessibilityValue {
    ArkUI_OptionalInt min;
    ArkUI_OptionalInt max;
    ArkUI_OptionalInt current;
    ArkUI_OptionalCharPtr text;
};

struct Keels_ArkUI_CustomSpanMeasureInfo {
    float fontSize;
};

struct Keels_ArkUI_CustomSpanMetrics {
    float width;
    float height;
};

struct Keels_ArkUI_CustomSpanDrawInfo {
    float optionsX;
    float optionsLineTop;
    float optionsLineBottom;
    float optionsBaseLine;
};

#ifdef __cplusplus
};
#endif

namespace Keels::Ace::NodeModel {

void NodeAddExtraData(Keels_ArkUI_NodeHandle node, Keels_ArkUI_NodeCustomEventType eventType, int32_t targetId, void* userData);
int32_t RegisterNodeCustomEvent(
    Keels_ArkUI_NodeHandle node, Keels_ArkUI_NodeCustomEventType eventType, int32_t targetId, void* userData);
void NodeRemoveExtraData(Keels_ArkUI_NodeHandle node, Keels_ArkUI_NodeCustomEventType eventType);
void UnregisterNodeCustomEvent(Keels_ArkUI_NodeHandle node, Keels_ArkUI_NodeCustomEventType eventType);
void RegisterNodeCustomReceiver(void (*eventReceiver)(Keels_ArkUI_NodeCustomEvent* event));
void UnregisterNodeCustomEventReceiver();
void HandleInnerCustomEvent(ArkUICustomNodeEvent* origin);
void HandleCustomEvent(Keels_ArkUI_NodeCustomEvent* event);
int32_t AddNodeCustomEventReceiver(Keels_ArkUI_NodeHandle nodePtr, void (*eventReceiver)(Keels_ArkUI_NodeCustomEvent* event));
int32_t RemoveNodeCustomEventReceiver(Keels_ArkUI_NodeHandle nodePtr, void (*eventReceiver)(Keels_ArkUI_NodeCustomEvent* event));
int32_t SetMeasuredSize(Keels_ArkUI_NodeHandle node, int32_t width, int32_t height);
int32_t SetLayoutPosition(Keels_ArkUI_NodeHandle node, int32_t positionX, int32_t positionY);
int32_t GetLayoutConstraint(Keels_ArkUI_NodeHandle node, Keels_ArkUI_LayoutConstraint* layoutConstraint);
Keels_ArkUI_IntSize GetMeasuredSize(Keels_ArkUI_NodeHandle node);
Keels_ArkUI_IntOffset GetLayoutPosition(Keels_ArkUI_NodeHandle node);
int32_t MeasureNode(Keels_ArkUI_NodeHandle node, Keels_ArkUI_LayoutConstraint* constraint);
int32_t LayoutNode(Keels_ArkUI_NodeHandle node, int32_t positionX, int32_t positionY);

uint32_t GetTotalChildCount(Keels_ArkUI_NodeHandle node);
Keels_ArkUI_NodeHandle GetChildAt(Keels_ArkUI_NodeHandle node, int32_t position);
Keels_ArkUI_NodeHandle GetFirstChild(Keels_ArkUI_NodeHandle node);
Keels_ArkUI_NodeHandle GetLastChild(Keels_ArkUI_NodeHandle node);
Keels_ArkUI_NodeHandle GetPreviousSibling(Keels_ArkUI_NodeHandle node);
Keels_ArkUI_NodeHandle GetNextSibling(Keels_ArkUI_NodeHandle node);
Keels_ArkUI_NodeHandle GetParent(Keels_ArkUI_NodeHandle node);
int32_t RemoveAllChildren(Keels_ArkUI_NodeHandle parentNode);
} // namespace Keels::Ace::NodeModel
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_EXTENED_H